package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UApplicationScenarios;
import com.ruoyi.system.service.IUApplicationScenariosService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据应用场景储备台账Controller
 * 
 * @author ruoyi
 * @date 2024-05-14
 */
@Controller
@RequestMapping("/system/scenarios")
public class UApplicationScenariosController extends BaseController
{
    private String prefix = "system/scenarios";

    @Autowired
    private IUApplicationScenariosService uApplicationScenariosService;

    @RequiresPermissions("system:scenarios:view")
    @GetMapping()
    public String scenarios()
    {
        return prefix + "/scenarios";
    }

    /**
     * 查询数据应用场景储备台账列表
     */
    @RequiresPermissions("system:scenarios:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UApplicationScenarios uApplicationScenarios)
    {
        startPage();
        List<UApplicationScenarios> list = uApplicationScenariosService.selectUApplicationScenariosList(uApplicationScenarios);
        return getDataTable(list);
    }

    /**
     * 导出数据应用场景储备台账列表
     */
    @RequiresPermissions("system:scenarios:export")
    @Log(title = "数据应用场景储备台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UApplicationScenarios uApplicationScenarios)
    {
        List<UApplicationScenarios> list = uApplicationScenariosService.selectUApplicationScenariosList(uApplicationScenarios);
        ExcelUtil<UApplicationScenarios> util = new ExcelUtil<UApplicationScenarios>(UApplicationScenarios.class);
        return util.exportExcel(list, "数据应用场景储备台账数据");
    }

    /**
     * 新增数据应用场景储备台账
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据应用场景储备台账
     */
    @RequiresPermissions("system:scenarios:add")
    @Log(title = "数据应用场景储备台账", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UApplicationScenarios uApplicationScenarios)
    {
        return toAjax(uApplicationScenariosService.insertUApplicationScenarios(uApplicationScenarios));
    }

    /**
     * 修改数据应用场景储备台账
     */
    @RequiresPermissions("system:scenarios:edit")
    @GetMapping("/edit/{catalogId}")
    public String edit(@PathVariable("catalogId") String catalogId, ModelMap mmap)
    {
        UApplicationScenarios uApplicationScenarios = uApplicationScenariosService.selectUApplicationScenariosByCatalogId(catalogId);
        mmap.put("uApplicationScenarios", uApplicationScenarios);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据应用场景储备台账
     */
    @RequiresPermissions("system:scenarios:edit")
    @Log(title = "数据应用场景储备台账", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UApplicationScenarios uApplicationScenarios)
    {
        return toAjax(uApplicationScenariosService.updateUApplicationScenarios(uApplicationScenarios));
    }

    /**
     * 删除数据应用场景储备台账
     */
    @RequiresPermissions("system:scenarios:remove")
    @Log(title = "数据应用场景储备台账", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(uApplicationScenariosService.deleteUApplicationScenariosByCatalogIds(ids));
    }
}
